<?php
defined('IN_SITE') or exit('Access Denied');

$C = subcat('goods');

switch($action)
{
    default:
		
		
		// 如果参数是自定义名称
		if(!$goodsid && $prefix){
			$result = $db->get_one("select `goodsid` from ".DB_PRE."goods where prefix = '$prefix'");
			$goodsid = $result['goodsid'];
			unset($result);
		} 
		
		// 主要获取该文章的栏目所在信息，例如详细页模板等等
		require_once 'goods.class.php';
		$goods = new goods();
		$r = $goods->get($goodsid);
		$C = cache_read('category_'.$r['catid'].'.php');
	
	
		
		// 获取该文章的所有内容信息
		require_once CACHE_MODEL_PATH.'goods_output.class.php';
		$out = new goods_output();
		$data = $out->get($r);
		extract($data);
	
		// 设置文章的头部信息、关键字等
		$title = strip_tags($title);
		$head['title'] = $title.'_'.$C['catname'].'_'.$SETTING['sitename'];
		$head['keywords'] = str_replace(' ', ',', $r['keywords']);
		$head['description'] = $r['description'];
		 
		if(!$C['defaultchargepoint'] && !$r['readpoint'])
		{
			header('Last-Modified: '.gmdate('D, d M Y H:i:s', $r['updatetime']).' GMT');
			header('Expires: '.gmdate('D, d M Y H:i:s', $r['updatetime']+CACHE_PAGE_CONTENT_TTL).' GMT');
			header('Cache-Control: max-age='.CACHE_PAGE_CONTENT_TTL.', must-revalidate');
		}
		include template('view.html','goods');
		cache_page(CACHE_PAGE_CONTENT_TTL);
	break;
	
	case 'index':
		include template('index.html','goods');
	break;
	
	case 'list':
		include template('list.html','goods');
	break;
	
	case 'groupbuy':
		include template('groupbuy.html','goods');
	break;
	
	case 'tag':
		$keyword = load('keyword.class.php','keyword');
		$data = $keyword->get($tag);
		if(!$data) showmessage("TAG: $tag 不存在！");
		$keyword->hits($tag);
		extract($data);
		
		// 所有tag标签连成的字符串，用于sql查询的时候where in()
		$data2 = $db->select("select `tag` from table_goods_tag t");
		foreach($data2 as $k=>$v){
			$tags .= !$tags ? $v['tag'] : ','.$v['tag'];
		}
		
		$head['title'] = $tag.'-'.$SETTING['sitename'];
		
		include template('tag.html');
	break;
	
	case 'view':
		$goodsid = $goodsid ? $goodsid : $id;
		
		// 主要获取该文章的栏目所在信息，例如详细页模板等等
		require_once MOD_ROOT.'goods/goods.class.php';
		$goods = new goods();
		$r = $goods->get($goodsid);
		$C = cache_read('category_'.$r['catid'].'.php');
	
		
		
		// 获取该文章的所有内容信息
		require_once CACHE_MODEL_PATH.'goods_output.class.php';
		$out = new goods_output();
		$data = $out->get($r);
		extract($data);
	
		// 设置文章的头部信息、关键字等
		$title = strip_tags($title);
		$head['title'] = $title.'_'.$C['catname'].'_'.$SETTING['sitename'];
		$head['keywords'] = str_replace(' ', ',', $r['keywords']);
		$head['description'] = $r['description'];
		
		if(!$C['defaultchargepoint'] && !$r['readpoint'])
		{
			header('Last-Modified: '.gmdate('D, d M Y H:i:s', $r['updatetime']).' GMT');
			header('Expires: '.gmdate('D, d M Y H:i:s', $r['updatetime']+CACHE_PAGE_CONTENT_TTL).' GMT');
			header('Cache-Control: max-age='.CACHE_PAGE_CONTENT_TTL.', must-revalidate');
		}
		
		include template('view.html','goods');
		cache_page(CACHE_PAGE_CONTENT_TTL);
	break;
}
?>